package com.endi.sap.service;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.endi.sap.dingding.CreateDingClient;
import com.endi.sap.entity.BaseInfo;
import com.endi.sap.enums.DingDingFormEnums;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

@Service
public class FormAndActionFactoryService {

    private static final Logger logger = LoggerFactory.getLogger(FormAndActionFactoryService.class);

    @Autowired
    private CustomerMaterialService customerMaterialService;

    @Autowired
    private CreateDingClient dingClient;

    public void factory(Map<String, Object> map) {

        String accessToken = (String) map.get("access_token");
        String formInsId = (String) map.get("formInsId");
        String formType = (String) map.get("formType");
        JSONArray userId = JSONObject.parseArray((String) map.get("userId"));
        BaseInfo baseInfo = dingClient.getClient(accessToken, String.valueOf(userId.get(0)));
        //判断参数是否为空
        if (StringUtils.isEmpty(accessToken)) {
            logger.info("accessToken禁止为空");
        }

        if (StringUtils.isEmpty(formInsId)) {
            logger.info("formInsId禁止为空");
        }
        if (StringUtils.isEmpty(formType)) {
            logger.info("formType禁止为空");
        }
        //获取表单标识码
        Integer formCode = DingDingFormEnums.getEnum(formType).getCode();
        //判断是哪个表单
        switch (formCode) {
            case 1:
                customerMaterialService.actionBuildFactory(baseInfo,map);
                break;
            case 2:
                System.out.println("数字是2");
                break;
            case 3:
                System.out.println("数字是3");
                break;
            default:
                logger.info("编码不存在");
        }

    }
}
